﻿picShare.service('userDataSvc', function (safeApply,$rootScope) {

    var pushAlbumNames = function (albumNamesArr) {

        if (albumNamesArr == null) {
            return [];
        }
        var albums = [];
        for (var i = 0; i < albumNamesArr.length; i++) {
            var currentName = {
                name: albumNamesArr[i]
            };
            albums.push(currentName);
        }
        return albums;
    };

    return {
        user: {
            id: null,
            userName: null,
            sessionKey: null,
            albumNames: null,
            userAlbumsAndPictures:null
        },
        putUserInfo: function (userId, userName, sessionKey, albumNames) {
            this.user.id = userId;
            this.user.userName = userName;
            this.user.sessionKey = sessionKey;
            this.user.albumNames = pushAlbumNames(albumNames);
            safeApply($rootScope);
        },
        pushNewAlbum: function (albName) {
            this.user.albumNames.push({ name: albName });
        }
    };
});